package com.jz.community.modulemine.mySgn;

import android.app.Activity;

import com.jz.community.basecomm.constant.AppConstants;
import com.jz.community.basecomm.constant.Constant;
import com.jz.community.basecomm.net.OkHttpUtil;
import com.jz.community.basecomm.task.ITaskCallbackListener;
import com.jz.community.basecomm.task.RxTask;
import com.jz.community.basecomm.utils.JsonUtils;
import com.jz.community.basecomm.utils.Preconditions;

import java.util.HashMap;
import java.util.List;

/**
 * Created by Tony.Fan on 2018/3/21 17:49
 */
public class SignAdvTask extends RxTask<String, Integer, List<SignAdvInfo>> {

    private Activity activity;
    private ITaskCallbackListener taskListener;

    public SignAdvTask(Activity activity,
                       ITaskCallbackListener taskListener) {
        super(activity);
        this.activity = activity;
        this.taskListener = taskListener;
    }

    @Override
    protected List<SignAdvInfo> doInBackground(String... params) {
        // 执行请求
        String result;
        result = OkHttpUtil.get(Constant.MEMBER_SIGN_ADV, getParam());
        List<SignAdvInfo> info = null;
        if (!Preconditions.isNullOrEmpty(result)) {
            info = JsonUtils.parseArray(result, SignAdvInfo.class);
        }
        return info;
    }

    @Override
    protected void onPostExecute(List<SignAdvInfo> result) {
        // 执行结果回调函数
        taskListener.doTaskComplete(result);
        super.onPostExecute(result);
    }

    @Override
    protected void onPreExecute() {
        super.onPreExecute();
    }

    @Override
    protected void onCancelled() {
        super.onCancelled();
    }

    /**
     * 获取请求所需的参数
     *
     * @param
     * @return
     */
    private HashMap<String, Object> getParam() {
        HashMap<String, Object> params = new HashMap<>();
        params.put("platformId", AppConstants.APPID);
        return params;
    }
}
